package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.CartDTO;
import com.iflytek.dto.PageDTO;
import com.iflytek.info.Cartinfo;
import com.iflytek.service.CartService;
import com.iflytek.vo.CartVO;
import com.iflytek.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/cart")
public class CartController{
    @Resource
    public CartService cartService;

    /**
     * 查询所有购物车（非分页）findAll
     * @return
     */
    @ApiOperation("查询全部")
    @GetMapping
    Result<Cartinfo> findAll(HttpServletRequest request){

        return cartService.findAll(request);
    }

    /**
     * 保存购物车save
     * @param dto
     * @return
     */
    @ApiOperation("保存")
    @PostMapping("")
    Result<Boolean> saveCart(@RequestBody CartDTO dto) {
        return cartService.saveCart(dto);
    }

    /**
     * 更新购物车信息update
     * @param dto
     * @return
     */
    @ApiOperation("更新")
    @PutMapping("")
    Result<Boolean> updateCart(@RequestBody CartDTO dto) {
        return cartService.updateCart(dto);
    }

    /**
     * 购物车分页查询findPage
     * @param dto
     * @return
     */
    @ApiOperation("分页")
    @GetMapping("/page")
    Result<PageVO<CartVO>> findPage(PageDTO<CartDTO> dto) {
        return cartService.findPage(dto);
    }


    /**
     * 购物车分页查询findById
     * @param id
     * @return
     */
    @ApiOperation("根据id查")
    @PostMapping("/{id}")
    Result<CartVO> findById(@PathVariable("id") Long id) {
        return cartService.findById(id);
    }

    /**
     * 根据id删除购物车deleteById
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    Result<CartVO> deleteById(@PathVariable("id") Long id) {
        return cartService.deleteById(id);
    }

}

